<template>
	<view class="address-wrapper">
		<view class="remind-choose">收货地址</view>
		<view class="container">
			<view class="input-item">
				<view class="form-item">
					<input class="input-box" v-model="addr.name" type="text" name="name" placeholder="请输入收货人姓名" maxlength="8">
				</view>
			</view>
			<view class="input-item">
				<view class="form-item">
					<input class="input-box" v-model="addr.phone" type="number" name="phone" maxlength="11" placeholder="手机号码">
				</view>
			</view>
			<view class="input-item">
				<view class="address-wrap" @click="showPCA">
					<view class="address-item">
						{{addr.province}}
					</view>                                                 
					<view class="address-item">                             
						{{addr.city}}                                       
					</view>                                                 
					<view class="address-item">                             
						{{addr.country}}                                    
					</view>
				</view>
				<!-- <view @click="showPCA">{{city?city:'省/市/区/街道'}}</view> -->
				<pcaPicker ref="pcaPicker" @confirm="getPCA"></pcaPicker>
			</view>
			<view class="input-item">
				<view class="form-item">
					<input class="input-box" v-model="addr.detail" type="text" name="detail" placeholder="小区门牌等详细信息">
				</view>
			</view>
			<view class="tips">
				*您提交的信息将加密发送
			</view>
		</view>
		<view class="determine" @click="submit">
			确认
		</view>
	</view>	
</template>

<script>
	import util from "../../util/util.js"
	export default {
		name:"sel-address",
		data() {
			return {
				addr:{
					name:"",
					phone:"",
					detail:"",
					province:"陕西省",
					city:"太原市",
					country:"市辖区"					
				}
			};
		},
		methods:{
			submit(){
				let addr = this.addr;
				if(addr.name==""||addr.name.length<2){
					uni.showToast({
						title:"请填写姓名",
						icon:"none"
					})
					return;
				}
				if(addr.phone == ""){
					uni.showToast({
						title:"请填写正确的手机号",
						icon:"none"
					})
					return;
				}
				if(!util.checkPhone(addr.phone)){
					uni.showToast({
						title:"请填写正确的手机号",
						icon:"none"
					})
					return;
				}
				if(this.city==""){
					uni.showToast({
						title:"请选择收货地区",
						icon:"none"
					})
					return;
				}
				if(addr.detail==""){
					uni.showToast({
						title:"请填写详细地址",
						icon:"none"
					})
					return;
				}				
				this.$emit('submit',this.addr)
				
			},
			showPCA(e){
				this.$refs.pcaPicker.show();
			},
			getPCA(e) {
				this.addr.province = e.province
				this.addr.city = e.city
				this.addr.country = e.country
			}
		}
	}
</script>

<style lang="scss" scoped>
	.address-wrapper{
		.remind-choose{
			width: 100%;
			margin: 40rpx auto 0;
			font-size: $uni-font-size-lg;
			font-weight: bold;
			padding-bottom: 10rpx;
		}
		.determine{
			width: 100%;
			height: 90rpx;
			line-height: 90rpx;
			color: #fff;
			background-color: $theme-color;
			text-align: center;
			border-radius: 5rpx;
			font-size: $uni-font-size-base;
		}
		.input-item,.address-wrap{
			width: 100%;
			height: 120rpx;
			border-bottom: 1px solid #d7d7d7;
			border-radius: 5rpx;
			.input-box{
				width: 100%;
				height: 120rpx;
				font-size: $uni-font-size-base;
			}
			.address-wrap{
				display: flex;
				align-items: center;
				font-size: $uni-font-size-base;
				.address-item{
					flex: 1;
					padding: 0 30rpx;
					position: relative;
					display: flex;
					align-items: center;
					&:before{
						content: "";
						position: absolute;
						right: 30rpx;
						width: 18rpx;
						height: 18rpx;
						background-image: url();
						background-repeat: no-repeat;
						background-size: 100% auto;
					}
				}
			}
		}
		.tips{
			width: 100%;
			height: 25rpx;
			margin: 60rpx auto 30rpx;
			font-size: $uni-font-size-sm;
			color: $theme-color;
		}
	}
</style>